home *** CD-ROM | disk | FTP | other *** search
/ Aminet 7 / Aminet 7 - August 1995.iso / Aminet / docs / misc / ConcNews.lha / news / general.programming / comp.lang.c_10274_000013.msg < prev    next >
Encoding:
Text File  |  1994-11-27  |  1.4 KB  |  34 lines

  1. Newsgroups: comp.lang.c
  2. Path: dd.chalmers.se!news.chalmers.se!sunic!pipex!hunts.x.co.uk!clive
  3. From: clive@sco.com (Clive D.W. Feather)
  4. Subject: Re: malloc(0)
  5. Sender: clive@x.co.uk (Clive Feather)
  6. Message-ID: <CLxF2A.DJ@x.co.uk>
  7. Date: Mon, 28 Feb 1994 08:46:58 GMT
  8. References: <plf.762372852@bert.cs.byu.edu>
  9. Organization: Santa Cruz Organization
  10. Lines: 22
  11.  
  12. In article <plf.762372852@bert.cs.byu.edu> plf@bert.cs.byu.edu (Paul L Fagerburg) writes:
  13. > What's the big deal about malloc(0)? It's really considered bad
  14. > programming style. The ANSI definition defines malloc(0) to return
  15. > a NULL pointer; it's that simple. Nobody on God's green earth
  16. > needs to allocate 0 bytes for use; it's usally to catch that one
  17. > exception that really shouldn't happen anyway if you're writing
  18. > clean code.
  19.  
  20. Gack, another idiot on the loose.
  21.  
  22. The ISO and ANSI standards both defined malloc(0) to be *either* NULL
  23. *or* a unique pointer (and there's a separate issue as to what "unique"
  24. means in this context, but I won't go into it).
  25.  
  26. While malloc(0) might not appear useful, being able to go realloc(ptr,0)
  27. is. Any code that dynamically resizes a buffer can potentially use it.
  28.  
  29. -- 
  30. Clive D.W. Feather     | Santa Cruz Operation    | If you lie to the compiler,
  31. clive@sco.com          | Croxley Centre          | it will get its revenge.
  32. Phone: +44 923 816 344 | Hatters Lane, Watford   |   - Henry Spencer
  33. Fax:   +44 923 210 352 | WD1 8YN, United Kingdom |
  34.